//
//  TutorialViewController.m
//  Ridding
//
//  Created by Wu Chenhao on 5/8/12.
//  Copyright (c) 2012 MicroStrategy. All rights reserved.
//

#import "TutorialViewController.h"
#import "ImageSwipeViewController.h"
#import "RiddingAppDelegate.h"

@implementation TutorialViewController

@synthesize tutorialImage;
@synthesize imageList;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewWillAppear:(BOOL)animated
{
  
    //appDelegate.navController.navigationBarHidden = YES;
    self.navigationController.navigationBarHidden = YES;
    [super viewWillAppear:animated];
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    //appDelegate.navController.navigationBarHidden = YES;
    //self.navigationController.navigationBarHidden = YES;
   	[super viewWillDisappear:animated];
}

- (void)viewDidLoad
{
//    [super viewDidLoad];
//    // Do any additional setup after loading the view from its nib.
//    imageList = [[NSArray alloc] initWithObjects:@"tutorial1", @"tutorial2", @"tutorial3", nil];
////    for (NSString *str in imageList) {
////        
////    }
//    tutorialImage.image = [UIImage imageNamed:@"tutorial1.jpg"];
    
    
    [super viewDidLoad];
    
//    self.navigationController.navigationBarHidden = NO;
    
//    CGSize size = CGSizeMake(320, 44);
//    UIImage *image = [self OriginImage:[UIImage imageNamed:@"navbg.png"] scaleToSize:size];
//    [self.navigationController.navigationBar setBackgroundImage:image
//                                                  forBarMetrics:UIBarMetricsDefault];
//    //设置导航栏按钮      
//    UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(back)];
//    [customBarItem setBackgroundImage:[UIImage imageNamed:@"返回按钮1.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//    [customBarItem setBackgroundImage:[UIImage imageNamed:@"返回按钮2.png"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
//    self.navigationItem.leftBarButtonItem = customBarItem;
//   
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
//    label.backgroundColor = [UIColor clearColor];
//    label.font = [UIFont boldSystemFontOfSize:20.0];
//    label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
//    label.textAlignment = UITextAlignmentCenter;
//    label.textColor = [UIColor whiteColor]; // change this color
//    self.navigationItem.titleView = label;
//    label.text = @"路线绘制教程";
//    [label sizeToFit];
    
    
	UIImage *img1=[UIImage imageNamed:@"help1.png"];
	UIImage *img2=[UIImage imageNamed:@"help2.png"];
	UIImage *img3=[UIImage imageNamed:@"help3.png"];
	
	NSArray *imgArray=[NSArray arrayWithObjects:img1,img2,img3,nil];
	imageSwipeViewController = [[ImageSwipeViewController alloc]initWithFrameRect:CGRectMake(0, 0, 320, 460) ImageArray:imgArray];
	
    UIImageView *startButton = [[UIImageView alloc] initWithFrame:CGRectMake(900, 200, 25, 25)];
    startButton.image=[UIImage imageNamed:@"bf.png"];
    
    startButton.userInteractionEnabled = YES;
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(back)];
    [startButton addGestureRecognizer:singleTap];

	[self.view addSubview:imageSwipeViewController.view];
     [imageSwipeViewController.scrollView addSubview:startButton];
    
}

-(void)back {  
    // Tell the controller to go back
    [self.navigationController popViewControllerAnimated:YES];
}
-(UIImage*)  OriginImage:(UIImage *)image   scaleToSize:(CGSize)size    
{    
    // 创建一个bitmap的context    
    // 并把它设置成为当前正在使用的context    
    UIGraphicsBeginImageContext(size);    
    
    // 绘制改变大小的图片    
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];    
    
    // 从当前context中创建一个改变大小后的图片    
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();    
    
    // 使当前的context出堆栈    
    UIGraphicsEndImageContext();    
    
    // 返回新的改变大小后的图片    
    return scaledImage;    
} 

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown);
}

@end
